<?php 

class Lemar_Banner
{
	
//-------------------------------------------------------------------------------------------------

	public static function showBanner($place)
	{
		$front = Zend_Controller_Front::getInstance();
		$controllerName = $front->getRequest()->getControllerName();
		$actionName = $front->getRequest()->getActionName();
		
		if (self::inListWithBanner($controllerName . ' ' . $actionName))
		{
			return self::getRandomBanner($place);
		}
		else
		{
			return '';
		}
	}		

//-------------------------------------------------------------------------------------------------
	public static function getRandomBanner($place = 'body-top')
	{
		$oRandom = models_BannersMapper::getRandom($place);
//		print_r($oRandom); die;
		if (isset($oRandom->id))
		{
			models_BannersstatsMapper::viewsAdd($oRandom->id);
			if ('image' == $oRandom->type)
			{
				$ret = '<a target="_blank" href="/index/gobanner/id/' . $oRandom->id .  '"><img src="' . $oRandom->content . '" alt="' . $oRandom->description . '" title="' . $oRandom->description . '" /></a>';
			}
			else
			{
				$ret = $oRandom->content;
			}			
			return $ret;
		}
		else 
		{
			return '';
		}
	}
	
	
//-------------------------------------------------------------------------------------------------

	public static function inListWithBanner($str)
	{
			return true;
		$aList = array('index index', 'news index', 'contactus index');
		
		if (in_array($str, $aList))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
//-------------------------------------------------------------------------------------------------
}